import { Server, Socket } from 'socket.io';

import commandTask from './command-task';
import addApplication from './other-task/add-application';
import addInfoUpdate from './other-task/app-info-update';

export default function (io: Server, socket: Socket): void {
  console.log('A user connected', socket.id);

  // 在线用户数量
  socket.emit('clientsCount', io.engine.clientsCount);

  // 任务
  socket.on('socket-task', ({ data, ev }) => {
    switch (ev) {
      case 'add-application':
        addApplication(socket, data);
        break;
      case 'command-task':
        commandTask(socket, data);
        break;
      case 'app-info-update':
        addInfoUpdate(socket, data);
        break;
    }
  });
}
